import dash
import feffery_antd_components as fac
from dash import html
from dash.dependencies import Input, Output, ALL

from server import app

layout = html.Div(
    [
        fac.AntdSpace(
            [
                fac.AntdButton(
                    f'按钮{i}',
                    id={
                        'type': 'tab5-demo-button',
                        'index': str(i)
                    }
                )
                for i in range(10)
            ],
            direction='vertical'
        ),
        fac.AntdDivider(isDashed=True),
        fac.AntdText(id='tab5-demo-output')
    ]
)


@app.callback(
    Output('tab5-demo-output', 'children'),
    Input({'type': 'tab5-demo-button', 'index': ALL}, 'nClicks')
)
def tab5_callback_demo(nClicksList):
    if any(nClicksList):
        return '总点击次数：{}'.format(sum([x for x in nClicksList if x]))

    return dash.no_update
